import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";
import tailwindcss from "tailwindcss";
import uniTailwind from "@uni-helper/vite-plugin-uni-tailwind";

// https://vitejs.dev/config/
// @ts-ignorelet
export default defineConfig(({ mode }) => {
  const root = process.cwd();
  const env = loadEnv(mode, root);
  return {
    css: {
      postcss: {
        plugins: [tailwindcss()],
      },
    },
    plugins: [uni(), uniTailwind()],
    build: {
      minify: true,
      target: "esnext", // 确保目标为 ES Modules
    },
    resolve: {
      //使用@路径
      alias: {
        "@": path.resolve("./src"),
      },
    },
    server: {
      https: false,
      port: "8067",
      proxy: {
        "/api": {
          target: env.VITE_BASE_API,
          changeOrigin: true,
          logLevel: "debug", // 显示代理日志
          // 根据项目后端进行配置， 因为实际后端是不需要api前缀的，所以这里需要rewrite一下
          // rewrite: (path) => path.replace("/api", ""),
        },
      },
    },
  };
});
